package com.etlmaster.executor.trans.core;

import java.io.Serializable;
import java.util.Map;

import com.etlmaster.executor.utils.DpExecutorUtils;
import com.etlmaster.executor.utils.ReflectionUtil;


/**
 * 行级处理器父类
 * 
 * @author wugf
 * @date 2016-04-29
 */
public abstract class LineTransProcessor implements Serializable {
	private String sourceTab;
	private String sourceCol;
	private String targetTab;
	private String targetCol;
	private String changeCode;
	private Map<String, Object> variables;

	public LineTransProcessor( String sourceTab,
			String sourceCol, String targetTab, String targetCol,
			String changeCode, Map paramStr, Map var) {

		this.setSourceTab(sourceTab);
		this.setSourceCol(sourceCol);
		this.setTargetCol(targetCol);
		this.setTargetTab(targetTab);
		this.setChangeCode(changeCode);
		this.variables = var;
		ReflectionUtil.parseParam(paramStr, this);
	}

	public abstract void transField(Line line);


	public int getFieldIndex(Line line) {
		String key=this.sourceTab+"_"+this.sourceCol;
		return line.getMeta().getColPosition(key);

	}
	public void updateMeta(LineMeta meta){
		if(!meta.getColIndex().containsKey(sourceTab+"_"+sourceCol)){
			meta.addField(sourceTab, sourceCol, targetTab, targetCol);
		}
	}


	public String getChangeCode() {
		return changeCode;
	}

	public void setChangeCode(String changeCode) {
		this.changeCode = changeCode;
	}

	public Map<String, Object> getVariables() {
		return variables;
	}

	public void setVariables(Map<String, Object> variables) {
		this.variables = variables;
	}

	protected String varaibleSubstution(String str) {
		return DpExecutorUtils.variableSubstitution( str, this.variables);
	}

	public String getSourceTab() {
		return sourceTab.toUpperCase();
	}

	public void setSourceTab(String sourceTab) {
		this.sourceTab = sourceTab;
	}

	public String getSourceCol() {
		return sourceCol.toUpperCase();
	}

	public void setSourceCol(String sourceCol) {
		this.sourceCol = sourceCol;
	}

	public String getTargetCol() {
		return targetCol;
	}

	public void setTargetCol(String targetCol) {
		this.targetCol = targetCol;
	}

	public String getTargetTab() {
		return targetTab;
	}

	public void setTargetTab(String targetTab) {
		this.targetTab = targetTab;
	}

}
